package com.jp.knowledge.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jp.knowledge.R;

/**
 * Created by jiayen on 16/9/27.
 */
public class ItemView extends LinearLayout {

    private View view;
    private Context mContext;

    private TextView name;
    private View underLine;
    private int postion;//记录所在位置
    public ItemView(Context context) {
        this(context,null);
    }

    public ItemView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public ItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mContext=context;
        init();
    }

    private void init() {
        view = LayoutInflater.from(mContext).inflate(R.layout.top_item_view,null);
        addView(view);
        name = (TextView) view.findViewById(R.id.item);
        underLine = view.findViewById(R.id.under_line);
    }

    /**
     * 设置item名称
     * @param str
     */
    public void setName(String str){
        name.setText(str);
    }

    public void setNameColor(int resId){
        name.setTextColor(getResources().getColor(resId));
        if(resId == R.color.theme_color)
            underLine.setVisibility(View.VISIBLE);
        else
            underLine.setVisibility(View.GONE);
    }

    public String getName(){
        return name.getText().toString();
    }
    public TextView getNameView() {
        return name;
    }

    public void setPostion(int postion){
            this.postion=postion;
    }

    public int getPostion() {
        return postion;
    }


}
